package service

import (
	"context"
	"elflog/module/module-account/model"
)

func (a *ModuleAccountService) InitData(ctx context.Context) {
	err := a.dao.Dao.Transaction(ctx, func(ctx context.Context) error {
		account, err := a.dao.GetAccountByName(ctx, "admin")
		if err != nil {
			return err
		}
		if account != nil {
			return nil
		}
		accountId, err := a.CreateAccount(ctx, "admin", "123456")
		if err != nil {
			return err
		}
		err = a.CreateLogger(ctx, &model.CreateAccountLoggerModel{
			AccountId:       accountId,
			Name:            "default",
			MaxSaveCount:    100000,
			MaxSaveDuration: 60 * 60 * 24 * 30,
			Key:             "123456",
			Secret:          "123456",
		})
		if err != nil {
			return err
		}
		return nil
	})
	if err != nil {
		panic(err)
	}
}
